package com.itheima;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HashMapPractice {
    public static void main(String[] args) {
        List<String> scProvince = new ArrayList<String>();
        scProvince.add("成都市");
        scProvince.add("宜宾市");
        scProvince.add("南充市");
        scProvince.add("自贡市");

        List<String> bjProvince = new ArrayList<String>();
        bjProvince.add("北京市");

        List<String> shProvince = new ArrayList<String>();
        shProvince.add("上海市");

        List<String> njProvince = new ArrayList<String>();
        njProvince.add("南京市");
        njProvince.add("六合市");


        Map<String,List<String>> map = new HashMap<>();
        map.put("四川", scProvince);
        map.put("北京", bjProvince);
        map.put("上海", shProvince);
        map.put("南京", njProvince);
        //调用printMap方法
        printMap(map);


    }
    public static void printMap(Map<String, List<String>> map) {
        map.forEach((key,value)->{

            String cityString;
            StringBuilder sb = new StringBuilder();

            //将value转换成特定字符串
            value.forEach(city->{
                sb.append(city+",");
            });

            //最后把sb中最后一个逗号去掉
            sb.deleteCharAt(sb.length()-1);

            String result = key + "="+ sb;
            System.out.println(result);
        });
    }
}
